package com.example.myapplication.view;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationSet;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.example.myapplication.R;

public class BtnItemView extends RelativeLayout {


    private TextView  btnTv;

    public BtnItemView(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.item_btn, this);
        btnTv = findViewById(R.id.btn);
    }

    public void setText(String txt) {
        btnTv.setText(txt);
    }

    public void setSelected(boolean checked) {
        float scale = 0.0f;
        if(checked) {
            btnTv.setBackgroundColor(Color.parseColor("#FF3F3F"));
            btnTv.setTextColor(Color.parseColor("#FFFFFF"));
            scale = 2.0f;
        } else {
            btnTv.setBackgroundColor(Color.parseColor("#4AF8D4"));
            btnTv.setTextColor(Color.parseColor("#000000"));
            scale = 1.0f;
        }
        AnimatorSet mAnimSet = new AnimatorSet();
        ObjectAnimator animatorX = ObjectAnimator.ofFloat(btnTv, View.ALPHA, 0.0f);
        ObjectAnimator animatorY = ObjectAnimator.ofFloat(btnTv, View.SCALE_Y, scale);
        ObjectAnimator animatorX2 = ObjectAnimator.ofFloat(btnTv, View.ALPHA, 1.0f);

        mAnimSet.setDuration(300);
        mAnimSet.playSequentially(animatorX,animatorX2);
        mAnimSet.start();


    }


}
